package com.ibeeking.found.common.config.secret;


import com.ibeeking.nematos.exception.BusinessException;
import com.ibeeking.nematos.utils.encryption.EncryptUtils;
import com.ibeeking.nematos.utils.json.JsonUtils;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;

import java.io.FileInputStream;
import java.io.InputStream;
import java.security.KeyStore;
import java.security.PrivateKey;
import java.security.PublicKey;
import java.util.List;

public class Test {

    public RsaConfig rsaConfigBean() {
        PrivateKey privateKey = null;
        PublicKey publicKey = null;
        try {
            KeyStore keyStore = KeyStore.getInstance("JKS");
            InputStream is =  new FileInputStream("d:/ibeeking.jks");
            keyStore.load(is, "Abcd@1234".toCharArray());
            privateKey = (PrivateKey) keyStore.getKey("ibeeking", "Abcd@1234".toCharArray());
            publicKey = keyStore.getCertificate("ibeeking").getPublicKey();
        } catch (Exception e) {
            throw new BusinessException("读取加密文件异常:" + e);
        }
        return new RsaConfig(publicKey, privateKey, "ibeeking");
    }

    public static void main(String[] args) {
        //String st = EncryptUtils.AesEncrypt.encrypt("Abcd@1234", "ibeeking");
        Test tt = new Test();
        RsaConfig ddd  = tt.rsaConfigBean();
        //String sdd = "MIIEogIBAAKCAQEAq4xPp57/PbbhJ7uiR369L7bUrkobEhPh43WT+ZCQ72rOZzfFxZPTSOp0Aa49RdmtwMZ+4H73ndZ2/ioReh1Huwaw0vKpPqeMxbNHH02W9GeeAZYYq5uNxjjfb/gG3rc+yRdo1UO91UqFpR6bVgZP+ukcgXM3R2POs0TZ6YVVjDq3/P6V5RQ8V9qkh6bufghgYoK8Opc6lRHZObTe0qlgz48mk4XyNe7wQWmO/7l/URwOPJ3taTu2VDoqVhtY3RPs37T7TxWh8w9sc4hh/sF9WMCSfFMnBjhxPiwQaPuQX/ImCBkyBpqGcMv7YKsjVacu4RQbcwvZZHBT9w2XQnsAaQIDAQABAoIBAA4SAhkzgf05L2/SL1Xsipk2m8HNM482BkRhHnP3wYuBl9BWKL3d3r86S62KRwhK+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0xszM2bAV56Awv1kVDFbTV0K9wdX1zZqDyuQYCEmS5vdT6OsdpXwA/LhnX9Uk2EfIaYuwc7SSqmDPCdzG1zkaaGVVGw=";
        String pubKey = EncryptUtils.RsaEncrypt.getPublicKey(ddd.getKeyPair().getPublic());
        String priKey = EncryptUtils.RsaEncrypt.getPrivateKey(ddd.getKeyPair().getPrivate());
        System.out.println(pubKey);
        System.out.println(priKey);
        pubKey = "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAq4xPp57/PbbhJ7uiR369L7bUrkobEhPh43WT+ZCQ72rOZzfFxZPTSOp0Aa49RdmtwMZ+4H73ndZ2/ioReh1Huwaw0vKpPqeMxbNHH02W9GeeAZYYq5uNxjjfb/gG3rc+yRdo1UO91UqFpR6bVgZP+ukcgXM3R2POs0TZ6YVVjDq3/P6V5RQ8V9qkh6bufghgYoK8Opc6lRHZObTe0qlgz48mk4XyNe7wQWmO/7l/URwOPJ3taTu2VDoqVhtY3RPs37T7TxWh8w9sc4hh/sF9WMCSfFMnBjhxPiwQaPuQX/ImCBkyBpqGcMv7YKsjVacu4RQbcwvZZHBT9w2XQnsAaQIDAQAB";
        priKey ="MIIEvAIBADANBgkqhkiG9w0BAQEFAASCBKYwggSiAgEAAoIBAQCrjE+nnv89tuEnu6JHfr0vttSuShsSE+HjdZP5kJDvas5nN8XFk9NI6nQBrj1F2a3Axn7gfved1nb+KhF6HUe7BrDS8qk+p4zFs0cfTZb0Z54Blhirm43GON9v+Abetz7JF2jVQ73VSoWlHptWBk/66RyBczdHY86zRNnphVWMOrf8/pXlFDxX2qSHpu5+CGBigrw6lzqVEdk5tN7SqWDPjyaThfI17vBBaY7/uX9RHA48ne1pO7ZUOipWG1jdE+zftPtPFaHzD2xziGH+wX1YwJJ8UycGOHE+LBBo+5Bf8iYIGTIGmoZwy/tgqyNVpy7hFBtzC9lkcFP3DZdCewBpAgMBAAECggEADhICGTOB/Tkvb9IvVeyKmTabwc0zjzYGRGEec/f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zMzZsBXnoDC/WRUMVtNXQr3B1fXNmoPK5BgISZLm91Po6x2lfAD8uGdf1STYR8hpi7BztJKqYM8J3MbXORpoZVUbA==";

        String encrypt = EncryptUtils.RsaEncrypt.encrypt("36", EncryptUtils.RsaEncrypt.getPublicKey(pubKey));
        System.out.println(encrypt);
        //encrypt = "Q9SHu1i/rXTedPBQW2sUi7BEcu/dfqOvRS/6cO9YiW8ShPIPpQZWMGIk1kXLoHgvdmhnA6pwTRAOBoCdNCZdWrCMD7As+CUZXLNnFSETg6Ah27XzZahTqzYQHpUjmUOnOGSYaBqDhfPNZfaAQCEyfrZ/WljX0e7JePIc22hQp6Q";
        String asc = "K6UhOc+BBAu3sVp11yykXCiFc0Se25hh7TofuqSH1GvNshV8W1/MXjpN4FTgwev6zxsmzJTJ6rQo/uXM7FWv5vIo5fge3nxTqQ3t3XLIbOrDZLCWKKAnz8HjFOwFfmz2EvyzxwPJX1Lky6464lMsZ3O0Q9E3zGrNKWCW9dxtoCCH77f8EDQ/g77fjxUm6zFXXu3tjbnOD08RCQMX82xnLimtsO3+4Ouym93uejfQxqcxQ+xJcjLK/+naQb827o+NP/X+Rq5MS5Fd/SHdWEDRUJu2Ev8ESqWkLYUUvXt73eCbWEFyN+KJxJ0ZNugE8y8qf06HWuIwuThANFuF5hJ8kA==";
        System.out.println(EncryptUtils.RsaEncrypt.decrypt(encrypt, EncryptUtils.RsaEncrypt.getPrivateKey(priKey)));
        System.out.println("test");
        String sdsf = "$2a$10$Qg.q5o1ZBVy/7TrV107u6ORr1Vyl.wm8AGU5tFcbpw2zPQuuxh82C";
        System.out.println(EncryptUtils.RsaEncrypt.decrypt(asc, EncryptUtils.RsaEncrypt.getPrivateKey(priKey)));

        String newPwd = EncryptUtils.RsaEncrypt.decrypt("123456", ddd.getKeyPair().getPrivate());
        PasswordEncoder passwordEncoder = new BCryptPasswordEncoder();
        String endoedPass = passwordEncoder.encode("123456");
        System.out.println("test");
        String  sdf = "[\"7005820666381732181\",\"7005820666381731539\",\"6871308413055008782\",\"6871308413000486800\",\"6871308413000486479\"]";
        List<Long> sdff = JsonUtils.jsonToList(sdf, Long.class);
    }
}
